let s:path = expand("<sfile>:p:h")

function! <SID>Correct(word)
if has('python3')
py3 << EOF
import vim
import os
import sys
sys.path.append(vim.eval("s:path"))
from dictionary import suggest, getCompleteItems

result = suggest(vim.eval("a:word"))
result = getCompleteItems(result)

vim.command("let ret = " + str(result))
EOF
return ret
endif
endfunction

function! auto#complete(findstart, base)
	if a:findstart
		" locate the start of the word
	    let line = getline('.')
	    let start = col('.') - 1
	    while start > 0 && line[start - 1] =~ '\a'
	      let start -= 1
	    endwhile
	    return start
	else
		" let word = getline('.')[0:col('.') - 1]
		let _result = <SID>Correct(a:base)
		return {'words': _result, 'refresh': 'always'}
	endif
endfunction

